// OperateDlg.cpp : implementation file
//

#include "stdafx.h"
#include "frontManage.h"
#include "OperateDlg.h"
#include "BookManageDlg.h"
#include "dataProcess.h"
#include "OrderDlg.h"
#include "PayDlg.h"
#include "CombineDlg.h"
#include "ExchangeDesk.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// COperateDlg dialog

IMPLEMENT_DYNAMIC(COperateDlg, CDialog)

COperateDlg::COperateDlg(CWnd* pParent /*=NULL*/)
	: CDialog(COperateDlg::IDD, pParent)
{
	nArea = 0;
	nDesktop = 0;
}

COperateDlg::~COperateDlg()
{
}

void COperateDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(COperateDlg, CDialog)
	ON_BN_CLICKED(IDC_BUTTON1, &COperateDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &COperateDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &COperateDlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_COMBINE, &COperateDlg::OnBnClickedCombine)
	ON_BN_CLICKED(IDC_ARRIVE, &COperateDlg::OnBnClickedArrive)
	ON_BN_CLICKED(IDC_EXCHANGE, &COperateDlg::OnBnClickedExchange)
	ON_BN_CLICKED(IDC_LEAVE, &COperateDlg::OnBnClickedLeave)
END_MESSAGE_MAP()


// COperateDlg message handlers

void COperateDlg::OnBnClickedButton1()
{
	CBookManageDlg dlg;
	const bookSetData& bookData = theData->getBookSetData();
	dlg.m_bookDay = bookData.m_preserveDay;
	const vector<areaInfo>& vArea = theData->getAreaInfo();
	dlg.m_deskName = vArea[nArea].desktops[nDesktop].deskName;
	dlg.m_areaName = vArea[nArea].areaName;
	dlg.DoModal();
	OnOK();
	// TODO: Add your control notification handler code here
}

BOOL COperateDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	SetWindowText(m_winName);
	

	netData getData = {dataProcessGetBookSetData,0,NULL};
	processMain(&getData,NULL);

	const vector<areaInfo>& vArea = theData->getAreaInfo();
	int nState = vArea[nArea].desktops[nDesktop].state;
	setDlgState(nState);
	// TODO:  Add extra initialization here

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void COperateDlg::OnBnClickedButton2()
{
	COrderDlg dlg;
	const vector<areaInfo>& vArea = theData->getAreaInfo();
	int nState = vArea[nArea].desktops[nDesktop].state;
	if (nState == DESKSTATE_RED_ORDER)
	{
		dlg.m_bFirstOrder = false;
	}
	dlg.nDesktop = nDesktop;
	dlg.nArea = nArea;
	dlg.DoModal();
	OnOK();
}

void COperateDlg::OnBnClickedButton3()
{
	CPayDlg dlg;
	dlg.nDesk = nDesktop;
	dlg.nArea = nArea;
	dlg.DoModal();
	// TODO: Add your control notification handler code here
	OnOK();
}

void COperateDlg::OnBnClickedCombine()
{
	CCombineDlg dlg;
	dlg.nArea = nArea;
	dlg.nDesk = nDesktop;
	dlg.DoModal();
	// TODO: Add your control notification handler code here
	OnOK();
}

void COperateDlg::OnBnClickedArrive()
{
	netData setState;
	setDeskState state;
	state.areaName[0] = 0;
	state.deskName[0] = 0;
	const vector<areaInfo>& vArea = theData->getAreaInfo();
	wcscpy_s(state.areaName,vArea[nArea].areaName);
	wcscpy_s(state.deskName,vArea[nArea].desktops[nDesktop].deskName);
	state.nState = DESKSTATE_RED;
	setState.buffer = (char*)&state;
	setState.bufferLength = sizeof(state);
	setState.type = dataProcessSetState;

	processMain(&setState,NULL);
	OnOK();

	// TODO: Add your control notification handler code here
}

void COperateDlg::setDlgState(int nState)
{
	CButton* pButton = NULL;
	if (nState == DESKSTATE_GREEN)
	{
		pButton = (CButton*)GetDlgItem(IDC_BUTTON1);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_BUTTON2);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_BUTTON3);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_COMBINE);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_ARRIVE);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_EXCHANGE);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_LEAVE);
		pButton->EnableWindow(FALSE);
	}
	else if (nState == DESKSTATE_RED)
	{
		pButton = (CButton*)GetDlgItem(IDC_BUTTON1);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_BUTTON2);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_BUTTON3);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_COMBINE);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_ARRIVE);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_EXCHANGE);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_LEAVE);
		pButton->EnableWindow();
	}
	else if (nState == DESKSTATE_YELLOW)
	{
		pButton = (CButton*)GetDlgItem(IDC_BUTTON1);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_BUTTON2);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_BUTTON3);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_COMBINE);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_ARRIVE);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_EXCHANGE);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_LEAVE);
		pButton->EnableWindow(FALSE);
	}
	else if (nState == DESKSTATE_RED_ORDER)
	{
		pButton = (CButton*)GetDlgItem(IDC_BUTTON1);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_BUTTON2);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_BUTTON3);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_COMBINE);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_ARRIVE);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_EXCHANGE);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_LEAVE);
		pButton->EnableWindow(FALSE);
	}
	else if (nState == DESKSTATE_RED_CASH)
	{
		pButton = (CButton*)GetDlgItem(IDC_BUTTON1);
		pButton->EnableWindow();
		pButton = (CButton*)GetDlgItem(IDC_BUTTON2);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_BUTTON3);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_COMBINE);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_ARRIVE);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_EXCHANGE);
		pButton->EnableWindow(FALSE);
		pButton = (CButton*)GetDlgItem(IDC_LEAVE);
		pButton->EnableWindow();
	}
}
void COperateDlg::OnBnClickedExchange()
{
	CExchangeDesk dlg;
	dlg.srcArea = nArea;// TODO: Add your control notification handler code here
	dlg.srcDesk = nDesktop;

	dlg.DoModal();
	OnOK();
}

void COperateDlg::OnBnClickedLeave()
{
	netData setState;
	setDeskState state;
	state.areaName[0] = 0;
	state.deskName[0] = 0;
	const vector<areaInfo>& vArea = theData->getAreaInfo();
	wcscpy_s(state.areaName,vArea[nArea].areaName);
	wcscpy_s(state.deskName,vArea[nArea].desktops[nDesktop].deskName);
	state.nState = DESKSTATE_GREEN;
	setState.buffer = (char*)&state;
	setState.bufferLength = sizeof(state);
	setState.type = dataProcessSetState;

	processMain(&setState,NULL);
	OnOK();
	// TODO: Add your control notification handler code here
}
